
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>模块 logging --- Python 的日志记录工具 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="logging.config --- 日志记录配置" href="logging.config.html" />
    <link rel="prev" title="getopt --- C 风格的命令行选项解析器" href="getopt.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/logging.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="logging.config.html" title="logging.config --- 日志记录配置"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="getopt.html" title="getopt --- C 风格的命令行选项解析器"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="allos.html" accesskey="U">通用操作系统服务</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-logging">
<span id="logging-logging-facility-for-python"></span><h1>模块 <a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> --- Python 的日志记录工具<a class="headerlink" href="#module-logging" title="永久链接至标题">¶</a></h1>
<p><strong>源代码:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/logging/__init__.py">Lib/logging/__init__.py</a></p>
<div class="sidebar" id="index-0">
<p class="sidebar-title">Important</p>
<p>此页面仅包含API参考信息。有关更多高级主题的教程信息和讨论，请参阅</p>
<ul class="simple">
<li><p><a class="reference internal" href="../howto/logging.html#logging-basic-tutorial"><span class="std std-ref">基础教程</span></a></p></li>
<li><p><a class="reference internal" href="../howto/logging.html#logging-advanced-tutorial"><span class="std std-ref">进阶教程</span></a></p></li>
<li><p><a class="reference internal" href="../howto/logging-cookbook.html#logging-cookbook"><span class="std std-ref">Logging Cookbook</span></a></p></li>
</ul>
</div>
<hr class="docutils" />
<p>这个模块为应用与库定义了实现灵活的事件日志系统的函数与类.</p>
<p>使用标准库提提供的 logging API 最主要的好处是，所有的 Python 模块都可能参与日志输出，包括你的日志消息和第三方模块的日志消息。</p>
<p>这个模块提供许多强大而灵活的功能。如果你对 logging 不太熟悉的话， 掌握它最好的方式就是查看它对应的教程（详见右侧的链接）。</p>
<p>该模块定义的基础类和函数都列在下面。</p>
<ul class="simple">
<li><p>记录器暴露了应用程序代码直接使用的接口。</p></li>
<li><p>处理程序将日志记录（由记录器创建）发送到适当的目标。</p></li>
<li><p>过滤器提供了更精细的附加功能，用于确定要输出的日志记录。</p></li>
<li><p>格式化程序指定最终输出中日志记录的样式。</p></li>
</ul>
<div class="section" id="logger-objects">
<span id="logger"></span><h2>Logger 对象<a class="headerlink" href="#logger-objects" title="永久链接至标题">¶</a></h2>
<p>Loggers 有以下的属性和方法。注意 <em>永远</em> 不要直接实例化 Loggers，应当通过模块级别的函数 <code class="docutils literal notranslate"><span class="pre">logging.getLogger(name)</span></code> 。多次使用相同的名字调用 <a class="reference internal" href="#logging.getLogger" title="logging.getLogger"><code class="xref py py-func docutils literal notranslate"><span class="pre">getLogger()</span></code></a> 会一直返回相同的 Logger 对象的引用。</p>
<p><code class="docutils literal notranslate"><span class="pre">name</span></code> 是潜在的周期分割层级值, 像``foo.bar.baz`` (例如, 抛出的可以只是明文的``foo``)。Loggers是进一步在子层次列表的更高loggers列表。例如，有个名叫``foo``的logger，名叫``foo.bar``，<code class="docutils literal notranslate"><span class="pre">foo.bar.baz</span></code>, 和 <code class="docutils literal notranslate"><span class="pre">foo.bam</span></code> 都是 <code class="docutils literal notranslate"><span class="pre">foo``的衍生logger.</span> <span class="pre">logger的名字分级类似Python</span> <span class="pre">包的层级,</span> <span class="pre">并且相同的如果你组织你的loggers在每模块级别基本上使用推荐的结构``logging.getLogger(__name__)</span></code>。这是因为在模块里，在Python包的命名空间的模块名为``__name__``。</p>
<dl class="class">
<dt id="logging.Logger">
<em class="property">class </em><code class="sig-prename descclassname">logging.</code><code class="sig-name descname">Logger</code><a class="headerlink" href="#logging.Logger" title="永久链接至目标">¶</a></dt>
<dd><dl class="attribute">
<dt id="logging.Logger.propagate">
<code class="sig-name descname">propagate</code><a class="headerlink" href="#logging.Logger.propagate" title="永久链接至目标">¶</a></dt>
<dd><p>如果这个属性为真，记录到这个记录器的事件将会传递给这个高级别管理器的记录器（原型），此外任何关联到这个记录器的管理器。消息会直接传递给原型记录器的管理器 - 既不是这个原型记录器的级别也不是过滤器是在考虑的问题。</p>
<p>如果等于假，记录消息将不会传递给这个原型记录器的管理器。</p>
<p>构造器将这个属性初始化为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>如果你关联了一个管理器*并且*到它自己的一个或多个记录器，它可能发出多次相同的记录。总体来说，你不需要关联管理器到一个或多个记录器 - 如果你只是关联它到一个合适的记录器等级中的最高级别记录器，它将会看到子记录器所有记录的事件，他们的传播剩下的设置为``True``。一个通用场景是只关联管理器到根记录器，并且让传播照顾剩下的.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.setLevel">
<code class="sig-name descname">setLevel</code><span class="sig-paren">(</span><em class="sig-param">level</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.setLevel" title="永久链接至目标">¶</a></dt>
<dd><p>给 logger 设置阈值为 <em>level</em> 。日志等级小于 <em>level</em> 会被忽略。严重性为 <em>level</em> 或更高的日志消息将由该 logger 的任何一个或多个 handler 发出，除非将处理程序的级别设置为比 <em>level</em> 更高的级别。</p>
<p>创建一个 logger 时，设置级别为 <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code>  （当 logger 是根 logger 时，将处理所有消息；当 logger 是非根 logger 时，所有消息会委派给父级）。注意根 logger 创建时使用的是 <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code> 级别。</p>
<p>委派给父级的意思是如果一个记录器的级别设置为NOTSET，遍历其祖先记录器链，直到找到另一个NOTSET级别的祖先或到达根为止。</p>
<p>如果发现某个父级的级别 不是NOTSET ，那么该父级的级别将被视为发起搜索的记录器的有效级别，并用于确定如何处理日志事件。</p>
<p>如果到达根 logger ，并且其级别为NOTSET，则将处理所有消息。否则，将使用根记录器的级别作为有效级别。</p>
<p>参见 <a class="reference internal" href="#levels"><span class="std std-ref">日志级别</span></a> 级别列表。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span>现在 <em>level</em> 参数可以接受形如 'INFO' 的级别字符串表示形式，以代替形如 <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> 的整数常量。 但是请注意，级别在内部存储为整数，并且 <a class="reference internal" href="#logging.Logger.getEffectiveLevel" title="logging.Logger.getEffectiveLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getEffectiveLevel()</span></code></a> 和 <a class="reference internal" href="#logging.Logger.isEnabledFor" title="logging.Logger.isEnabledFor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isEnabledFor()</span></code></a> 等方法的传入/返回值也为整数。</p>
</div>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.isEnabledFor">
<code class="sig-name descname">isEnabledFor</code><span class="sig-paren">(</span><em class="sig-param">level</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.isEnabledFor" title="永久链接至目标">¶</a></dt>
<dd><p>指示此记录器是否将处理级别为 <em>level</em> 的消息。此方法首先检查由 <code class="docutils literal notranslate"><span class="pre">logging.disable(level)</span></code> 设置的模块级的级别，然后检查由 <a class="reference internal" href="#logging.Logger.getEffectiveLevel" title="logging.Logger.getEffectiveLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getEffectiveLevel()</span></code></a> 确定的记录器的有效级别。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.getEffectiveLevel">
<code class="sig-name descname">getEffectiveLevel</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.getEffectiveLevel" title="永久链接至目标">¶</a></dt>
<dd><p>指示此记录器的有效级别。如果通过 <a class="reference internal" href="#logging.Logger.setLevel" title="logging.Logger.setLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setLevel()</span></code></a> 设置了除 <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code> 以外的值，则返回该值。否则，将层次结构遍历到根，直到找到除 <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code> 以外的其他值，然后返回该值。返回的值是一个整数，通常为 <code class="xref py py-const docutils literal notranslate"><span class="pre">logging.DEBUG</span></code>、 <code class="xref py py-const docutils literal notranslate"><span class="pre">logging.INFO</span></code> 等等。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.getChild">
<code class="sig-name descname">getChild</code><span class="sig-paren">(</span><em class="sig-param">suffix</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.getChild" title="永久链接至目标">¶</a></dt>
<dd><p>返回由后缀确定的，是该记录器的后代的记录器。 因此，<code class="docutils literal notranslate"><span class="pre">logging.getLogger('abc').getChild('def.ghi')</span></code> 与 <code class="docutils literal notranslate"><span class="pre">logging.getLogger('abc.def.ghi')</span></code> 将返回相同的记录器。 这是一个便捷方法，当使用如 <code class="docutils literal notranslate"><span class="pre">__name__</span></code> 而不是字符串字面值命名父记录器时很有用。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.debug">
<code class="sig-name descname">debug</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.debug" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code> on this logger. The <em>msg</em> is the
message format string, and the <em>args</em> are the arguments which are merged into
<em>msg</em> using the string formatting operator. (Note that this means that you can
use keywords in the format string, together with a single dictionary argument.)</p>
<p>There are three keyword arguments in <em>kwargs</em> which are inspected:
<em>exc_info</em>, <em>stack_info</em>, and <em>extra</em>.</p>
<p>如果 <em>exc_info</em> 的求值结果不为 false，则它将异常信息添加到日志消息中。如果提供了一个异常元组（按照 <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> 返回的格式）或一个异常实例，则将其使用；否则，调用 <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> 以获取异常信息。</p>
<p>第二个可选关键字参数是 <em>stack_info</em>，默认为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。如果为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则将堆栈信息添加到日志消息中，包括实际的日志调用。请注意，这与通过指定 <em>exc_info</em> 显示的堆栈信息不同：前者是从堆栈底部到当前线程中的日志记录调用的堆栈帧，而后者是在搜索异常处理程序时，跟踪异常而打开的堆栈帧的信息。</p>
<p>您可以独立于 <em>exc_info</em> 来指定 <em>stack_info</em>，例如，即使在未引发任何异常的情况下，也可以显示如何到达代码中的特定点。堆栈帧在标题行之后打印：</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Stack (most recent call last):
</pre></div>
</div>
<p>这模仿了显示异常帧时所使用的 <code class="docutils literal notranslate"><span class="pre">Traceback</span> <span class="pre">(most</span> <span class="pre">recent</span> <span class="pre">call</span> <span class="pre">last):</span></code> 。</p>
<p>The third keyword argument is <em>extra</em> which can be used to pass a
dictionary which is used to populate the __dict__ of the LogRecord created for
the logging event with user-defined attributes. These custom attributes can then
be used as you like. For example, they could be incorporated into logged
messages. For example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">FORMAT</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%(asctime)-15s</span><span class="s1"> </span><span class="si">%(clientip)s</span><span class="s1"> </span><span class="si">%(user)-8s</span><span class="s1"> </span><span class="si">%(message)s</span><span class="s1">&#39;</span>
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="nb">format</span><span class="o">=</span><span class="n">FORMAT</span><span class="p">)</span>
<span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;clientip&#39;</span><span class="p">:</span> <span class="s1">&#39;192.168.0.1&#39;</span><span class="p">,</span> <span class="s1">&#39;user&#39;</span><span class="p">:</span> <span class="s1">&#39;fbloggs&#39;</span><span class="p">}</span>
<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;tcpserver&#39;</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;Protocol problem: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="s1">&#39;connection reset&#39;</span><span class="p">,</span> <span class="n">extra</span><span class="o">=</span><span class="n">d</span><span class="p">)</span>
</pre></div>
</div>
<p>输出类似于</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>2006-02-08 22:20:02,165 192.168.0.1 fbloggs  Protocol problem: connection reset
</pre></div>
</div>
<p>The keys in the dictionary passed in <em>extra</em> should not clash with the keys used
by the logging system. (See the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> documentation for more
information on which keys are used by the logging system.)</p>
<p>If you choose to use these attributes in logged messages, you need to exercise
some care. In the above example, for instance, the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> has been
set up with a format string which expects 'clientip' and 'user' in the attribute
dictionary of the LogRecord. If these are missing, the message will not be
logged because a string formatting exception will occur. So in this case, you
always need to pass the <em>extra</em> dictionary with these keys.</p>
<p>尽管这可能很烦人，但此功能旨在用于特殊情况，例如在多个上下文中执行相同代码的多线程服务器，并且出现的有趣条件取决于此上下文（例如在上面的示例中就是远程客户端IP地址和已验证用户名）。在这种情况下，很可能将专门的 <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> 与特定的 <a class="reference internal" href="#logging.Handler" title="logging.Handler"><code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code></a> 一起使用。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能: </span>增加了 <em>stack_info</em> 参数。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版更改: </span>The <em>exc_info</em> parameter can now accept exception instances.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.info">
<code class="sig-name descname">info</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.info" title="永久链接至目标">¶</a></dt>
<dd><p>在此记录器上记录 <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> 级别的消息。参数解释同 <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.warning">
<code class="sig-name descname">warning</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.warning" title="永久链接至目标">¶</a></dt>
<dd><p>在此记录器上记录 <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code> 级别的消息。参数解释同 <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>有一个功能上与 <code class="docutils literal notranslate"><span class="pre">warning</span></code> 一致的方法 <code class="docutils literal notranslate"><span class="pre">warn</span></code>。由于 <code class="docutils literal notranslate"><span class="pre">warn</span></code> 已被弃用，请不要使用它 —— 改为使用 <code class="docutils literal notranslate"><span class="pre">warning</span></code>。</p>
</div>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.error">
<code class="sig-name descname">error</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.error" title="永久链接至目标">¶</a></dt>
<dd><p>在此记录器上记录 <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> 级别的消息。参数解释同 <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.critical">
<code class="sig-name descname">critical</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.critical" title="永久链接至目标">¶</a></dt>
<dd><p>在此记录器上记录 <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code> 级别的消息。参数解释同 <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.log">
<code class="sig-name descname">log</code><span class="sig-paren">(</span><em class="sig-param">level</em>, <em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.log" title="永久链接至目标">¶</a></dt>
<dd><p>在此记录器上记录 <em>level</em> 整数代表的级别的消息。参数解释同 <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.exception">
<code class="sig-name descname">exception</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.exception" title="永久链接至目标">¶</a></dt>
<dd><p>在此记录器上记录 <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> 级别的消息。参数解释同 <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>。异常信息将添加到日志消息中。仅应从异常处理程序中调用此方法。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.addFilter">
<code class="sig-name descname">addFilter</code><span class="sig-paren">(</span><em class="sig-param">filter</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.addFilter" title="永久链接至目标">¶</a></dt>
<dd><p>将指定的过滤器 <em>filter</em> 添加到此记录器。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.removeFilter">
<code class="sig-name descname">removeFilter</code><span class="sig-paren">(</span><em class="sig-param">filter</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.removeFilter" title="永久链接至目标">¶</a></dt>
<dd><p>从此记录器中删除指定的处理程序 <em>filter</em>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.filter">
<code class="sig-name descname">filter</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.filter" title="永久链接至目标">¶</a></dt>
<dd><p>将此记录器的过滤器应用于记录，如果记录能被处理则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。过滤器会被依次使用，直到其中一个返回假值为止。如果它们都不返回假值，则记录将被处理（传递给处理器）。如果返回任一为假值，则不会对该记录做进一步处理。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.addHandler">
<code class="sig-name descname">addHandler</code><span class="sig-paren">(</span><em class="sig-param">hdlr</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.addHandler" title="永久链接至目标">¶</a></dt>
<dd><p>将指定的处理程序 <em>hdlr</em> 添加到此记录器。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.removeHandler">
<code class="sig-name descname">removeHandler</code><span class="sig-paren">(</span><em class="sig-param">hdlr</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.removeHandler" title="永久链接至目标">¶</a></dt>
<dd><p>从此记录器中删除指定的处理器 <em>hdlr</em>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.findCaller">
<code class="sig-name descname">findCaller</code><span class="sig-paren">(</span><em class="sig-param">stack_info=False</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.findCaller" title="永久链接至目标">¶</a></dt>
<dd><p>查找调用源的文件名和行号，以 文件名，行号，函数名称和堆栈信息 4元素元组的形式返回。堆栈信息将返回 <code class="docutils literal notranslate"><span class="pre">None``除非</span> <span class="pre">*stack_info*</span> <span class="pre">为</span> <span class="pre">``True</span></code>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.handle">
<code class="sig-name descname">handle</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.handle" title="永久链接至目标">¶</a></dt>
<dd><p>通过将记录传递给与此记录器及其祖先关联的所有处理器来处理（直到某个 <em>propagate</em> 值为 false）。此方法用于从套接字接收的未序列化的以及在本地创建的记录。使用 <a class="reference internal" href="#logging.Logger.filter" title="logging.Logger.filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">filter()</span></code></a> 进行记录程序级别过滤。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.makeRecord">
<code class="sig-name descname">makeRecord</code><span class="sig-paren">(</span><em class="sig-param">name</em>, <em class="sig-param">level</em>, <em class="sig-param">fn</em>, <em class="sig-param">lno</em>, <em class="sig-param">msg</em>, <em class="sig-param">args</em>, <em class="sig-param">exc_info</em>, <em class="sig-param">func=None</em>, <em class="sig-param">extra=None</em>, <em class="sig-param">sinfo=None</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.makeRecord" title="永久链接至目标">¶</a></dt>
<dd><p>这是一种工厂方法，可以在子类中对其进行重写以创建专门的 <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 实例。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Logger.hasHandlers">
<code class="sig-name descname">hasHandlers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.hasHandlers" title="永久链接至目标">¶</a></dt>
<dd><p>检查此记录器是否配置了任何处理器。通过在此记录器及其记录器层次结构中的父级中查找处理器完成此操作。如果找到处理器则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>，否则返回``False``。只要找到 “propagate” 属性设置为 false的记录器，该方法就会停止搜索层次结构 —— 其将是最后一个检查处理器是否存在的记录器。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版更改: </span>现在可以对处理器进行序列化和反序列化。</p>
</div>
</dd></dl>

</div>
<div class="section" id="logging-levels">
<span id="levels"></span><h2>日志级别<a class="headerlink" href="#logging-levels" title="永久链接至标题">¶</a></h2>
<p>日志记录级别的数值在下表中给出。如果你想要定义自己的级别，并且需要它们具有相对于预定义级别的特定值，那么这些内容可能是你感兴趣的。如果你定义具有相同数值的级别，它将覆盖预定义的值; 预定义的名称丢失。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 48%" />
<col style="width: 52%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>级别</p></th>
<th class="head"><p>数值</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code></p></td>
<td><p>50</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ERROR</span></code></p></td>
<td><p>40</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">WARNING</span></code></p></td>
<td><p>30</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">INFO</span></code></p></td>
<td><p>20</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">DEBUG</span></code></p></td>
<td><p>10</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">NOTSET</span></code></p></td>
<td><p>0</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="handler-objects">
<span id="handler"></span><h2>处理器对象<a class="headerlink" href="#handler-objects" title="永久链接至标题">¶</a></h2>
<p>Handler 有以下属性和方法。注意不要直接实例化 <a class="reference internal" href="#logging.Handler" title="logging.Handler"><code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code></a> ；这个类用来派生其他更有用的子类。但是，子类的 <a class="reference internal" href="../reference/datamodel.html#object.__init__" title="object.__init__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code></a> 方法需要调用 <a class="reference internal" href="#logging.Handler.__init__" title="logging.Handler.__init__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Handler.__init__()</span></code></a> 。</p>
<dl class="class">
<dt id="logging.Handler">
<em class="property">class </em><code class="sig-prename descclassname">logging.</code><code class="sig-name descname">Handler</code><a class="headerlink" href="#logging.Handler" title="永久链接至目标">¶</a></dt>
<dd><dl class="method">
<dt id="logging.Handler.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param">level=NOTSET</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.__init__" title="永久链接至目标">¶</a></dt>
<dd><p>初始化 <a class="reference internal" href="#logging.Handler" title="logging.Handler"><code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code></a> 实例时，需要设置它的级别，将过滤列表置为空，并且创建锁（通过 <a class="reference internal" href="#logging.Handler.createLock" title="logging.Handler.createLock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createLock()</span></code></a> ）来序列化对 I/O 的访问。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.createLock">
<code class="sig-name descname">createLock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.createLock" title="永久链接至目标">¶</a></dt>
<dd><p>初始化一个线程锁，用来序列化对底层的 I/O 功能的访问，底层的 I/O 功能可能不是线程安全的。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.acquire">
<code class="sig-name descname">acquire</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.acquire" title="永久链接至目标">¶</a></dt>
<dd><p>使用 <a class="reference internal" href="#logging.Handler.createLock" title="logging.Handler.createLock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createLock()</span></code></a>  获取线程锁。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.release">
<code class="sig-name descname">release</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.release" title="永久链接至目标">¶</a></dt>
<dd><p>使用 <a class="reference internal" href="#logging.Handler.acquire" title="logging.Handler.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">acquire()</span></code></a> 来释放线程锁。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.setLevel">
<code class="sig-name descname">setLevel</code><span class="sig-paren">(</span><em class="sig-param">level</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.setLevel" title="永久链接至目标">¶</a></dt>
<dd><p>给处理器设置阈值为 <em>level</em> 。日志级别小于 <em>level</em> 将被忽略。创建处理器时，日志级别被设置为 <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code> （所有的消息都会被处理）。</p>
<p>参见 <a class="reference internal" href="#levels"><span class="std std-ref">日志级别</span></a> 级别列表。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span><em>level</em> 形参现在接受像 'INFO' 这样的字符串形式的级别表达方式，也可以使用像 <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> 这样的整数常量。</p>
</div>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.setFormatter">
<code class="sig-name descname">setFormatter</code><span class="sig-paren">(</span><em class="sig-param">fmt</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.setFormatter" title="永久链接至目标">¶</a></dt>
<dd><p>将此处理器的 <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> 设置为 <em>fmt</em>。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.addFilter">
<code class="sig-name descname">addFilter</code><span class="sig-paren">(</span><em class="sig-param">filter</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.addFilter" title="永久链接至目标">¶</a></dt>
<dd><p>将指定的过滤器 <em>filter</em> 添加到此处理器。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.removeFilter">
<code class="sig-name descname">removeFilter</code><span class="sig-paren">(</span><em class="sig-param">filter</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.removeFilter" title="永久链接至目标">¶</a></dt>
<dd><p>从此处理器中删除指定的过滤器 <em>filter</em> 。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.filter">
<code class="sig-name descname">filter</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.filter" title="永久链接至目标">¶</a></dt>
<dd><p>将此处理器的过滤器应用于记录，在要处理记录时返回 <code class="docutils literal notranslate"><span class="pre">True</span></code> 。依次查询过滤器，直到其中一个返回假值为止。如果它们都不返回假值，则将发出记录。如果返回一个假值，则处理器将不会发出记录。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.flush">
<code class="sig-name descname">flush</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.flush" title="永久链接至目标">¶</a></dt>
<dd><p>确保所有日志记录从缓存输出。此版本不执行任何操作，并且应由子类实现。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.close">
<code class="sig-name descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.close" title="永久链接至目标">¶</a></dt>
<dd><p>整理处理器使用的所有资源。此版本不输出，但从内部处理器列表中删除处理器，内部处理器在 <a class="reference internal" href="#logging.shutdown" title="logging.shutdown"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutdown()</span></code></a> 被调用时关闭 。子类应确保从重写的 <a class="reference internal" href="#logging.Handler.close" title="logging.Handler.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> 方法中调用此方法。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.handle">
<code class="sig-name descname">handle</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.handle" title="永久链接至目标">¶</a></dt>
<dd><p>经已添加到处理器的过滤器过滤后，有条件地发出指定的日志记录。用获取/释放 I/O 线程锁包装记录的实际发出行为。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.handleError">
<code class="sig-name descname">handleError</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.handleError" title="永久链接至目标">¶</a></dt>
<dd><p>调用 <a class="reference internal" href="#logging.Handler.emit" title="logging.Handler.emit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code></a> 期间遇到异常时，应从处理器中调用此方法。如果模块级属性 <code class="docutils literal notranslate"><span class="pre">raiseExceptions</span></code> 是 <code class="docutils literal notranslate"><span class="pre">False</span></code>，则异常将被静默忽略。这是大多数情况下日志系统需要的 —— 大多数用户不会关心日志系统中的错误，他们对应用程序错误更感兴趣。但是，你可以根据需要将其替换为自定义处理器。指定的记录是发生异常时正在处理的记录。（<code class="docutils literal notranslate"><span class="pre">raiseExceptions</span></code> 的默认值是 <code class="docutils literal notranslate"><span class="pre">True</span></code>，因为这在开发过程中是比较有用的）。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.format">
<code class="sig-name descname">format</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.format" title="永久链接至目标">¶</a></dt>
<dd><p>如果设置了格式器则用其对记录进行格式化。否则，使用模块的默认格式器。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Handler.emit">
<code class="sig-name descname">emit</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.emit" title="永久链接至目标">¶</a></dt>
<dd><p>执行实际记录给定日志记录所需的操作。这个版本应由子类实现，因此这里直接引发 <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> 异常。</p>
</dd></dl>

</dd></dl>

<p>有关作为标准随附的处理程序，请参见 <a class="reference internal" href="logging.handlers.html#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>。</p>
</div>
<div class="section" id="formatter-objects">
<span id="id1"></span><h2>格式器对象<a class="headerlink" href="#formatter-objects" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> 对象拥有以下的属性和方法。一般情况下，它们负责将 <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 转换为可由人或外部系统解释的字符串。基础的 <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> 允许指定格式字符串。如果未提供任何值，则使用默认值 <code class="docutils literal notranslate"><span class="pre">'%(message)s'</span></code> ，它仅将消息包括在日志记录调用中。要在格式化输出中包含其他信息（如时间戳），请阅读下文。</p>
<p>格式器可以使用格式化字符串来初始化，该字符串利用 <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 的属性 —— 例如上述默认值，用户的消息和参数预先格式化为 <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 的 <em>message</em> 属性后被使用。此格式字符串包含标准的 Python %-s 样式映射键。有关字符串格式的更多信息，请参见 <a class="reference internal" href="stdtypes.html#old-string-formatting"><span class="std std-ref">printf 风格的字符串格式化</span></a>。</p>
<p>The useful mapping keys in a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> are given in the section on
<a class="reference internal" href="#logrecord-attributes"><span class="std std-ref">LogRecord 属性</span></a>.</p>
<dl class="class">
<dt id="logging.Formatter">
<em class="property">class </em><code class="sig-prename descclassname">logging.</code><code class="sig-name descname">Formatter</code><span class="sig-paren">(</span><em class="sig-param">fmt=None</em>, <em class="sig-param">datefmt=None</em>, <em class="sig-param">style='%'</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> 类的新实例。实例将使用整个消息的格式字符串以及消息的日期/时间部分的格式字符串进行初始化。如果未指定 <em>fmt</em> ，则使用 <code class="docutils literal notranslate"><span class="pre">'%(message)s'</span></code>。如果未指定 <em>datefmt</em>，则使用  <a class="reference internal" href="#logging.Formatter.formatTime" title="logging.Formatter.formatTime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatTime()</span></code></a> 文档中描述的格式。</p>
<p>The <em>style</em> parameter can be one of '%', '{' or '$' and determines how
the format string will be merged with its data: using one of %-formatting,
<a class="reference internal" href="stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> or <a class="reference internal" href="string.html#string.Template" title="string.Template"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Template</span></code></a>. See <a class="reference internal" href="../howto/logging-cookbook.html#formatting-styles"><span class="std std-ref">Using particular formatting styles throughout your application</span></a>
for more information on using {- and $-formatting for log messages.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span><em>style</em>  参数已加入.</p>
</div>
<dl class="method">
<dt id="logging.Formatter.format">
<code class="sig-name descname">format</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter.format" title="永久链接至目标">¶</a></dt>
<dd><p>记录的属性字典用作字符串格式化操作的参数。返回结果字符串。在格式化字典之前，需要执行几个准备步骤。 使用 <em>msg</em> % <em>args</em> 计算记录的 <em>message</em> 属性。如果格式化字符串包含 <code class="docutils literal notranslate"><span class="pre">'(asctime)'</span></code>，则调用 <a class="reference internal" href="#logging.Formatter.formatTime" title="logging.Formatter.formatTime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatTime()</span></code></a> 来格式化事件时间。如果有异常信息，则使用 <a class="reference internal" href="#logging.Formatter.formatException" title="logging.Formatter.formatException"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatException()</span></code></a> 将其格式化并附加到消息中。请注意，格式化的异常信息缓存在属性 <em>exc_text</em> 中。这很有用，因为可以对异常信息进行序列化并通过网络发送，但是如果您有不止一个定制了异常信息格式的 <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> 子类，则应格外小心。在这种情况下，您必须在格式器完成格式化后清除缓存的值，以便下一个处理事件的格式化程序不使用缓存的值，而是重新计算它。</p>
<p>如果栈信息可用，它将被添加在异常信息之后，如有必要请使用 <a class="reference internal" href="#logging.Formatter.formatStack" title="logging.Formatter.formatStack"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatStack()</span></code></a> 来转换它。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Formatter.formatTime">
<code class="sig-name descname">formatTime</code><span class="sig-paren">(</span><em class="sig-param">record</em>, <em class="sig-param">datefmt=None</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter.formatTime" title="永久链接至目标">¶</a></dt>
<dd><p>此方法应由想要使用格式化时间的格式器中的 <a class="reference internal" href="functions.html#format" title="format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format()</span></code></a> 调用。可以在格式器中重写此方法以提供任何特定要求，但是基本行为如下：如果指定了 <em>datefmt</em> （字符串），则将其用于 <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> 来格式化记录的创建时间。否则，使用格式 '%Y-%m-%d %H:%M:%S,uuu'，其中 uuu 部分是毫秒值，其他字母根据 <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> 文档。这种时间格式的示例为 <code class="docutils literal notranslate"><span class="pre">2003-01-23</span> <span class="pre">00:29:50,411</span></code>。返回结果字符串。</p>
<p>此函数使用一个用户可配置函数将创建时间转换为元组。 默认情况下，使用 <a class="reference internal" href="time.html#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.localtime()</span></code></a>；要为特定格式化程序实例更改此项，请将实例的 <code class="docutils literal notranslate"><span class="pre">converter</span></code> 属性设为具有与 <a class="reference internal" href="time.html#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.localtime()</span></code></a> 或 <a class="reference internal" href="time.html#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.gmtime()</span></code></a> 相同签名的函数。 要为所有格式化程序更改此项，例如当你希望所有日志时间都显示为 GMT，请在 <code class="docutils literal notranslate"><span class="pre">Formatter</span></code> 类中设置 <code class="docutils literal notranslate"><span class="pre">converter</span></code> 属性。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.3 版更改: </span>在之前版本中，默认格式为写死的代码，例如这个例子: <code class="docutils literal notranslate"><span class="pre">2010-09-06</span> <span class="pre">22:38:15,292</span></code> 其中逗号之前的部分由 strptime 格式字符串 (<code class="docutils literal notranslate"><span class="pre">'%Y-%m-%d</span> <span class="pre">%H:%M:%S'</span></code>) 处理，而逗号之后的部分为毫秒值。 因为 strptime 没有表示毫秒的占位符，毫秒值使用了另外的格式字符串来添加 <code class="docutils literal notranslate"><span class="pre">'%s,%03d'</span></code> --- 这两个格式字符串代码都是写死在该方法中的。 经过修改，这些字符串被定义为类层级的属性，当需要时可以在实例层级上被重载。 属性的名称为 <code class="docutils literal notranslate"><span class="pre">default_time_format</span></code> (用于 strptime 格式字符串) 和 <code class="docutils literal notranslate"><span class="pre">default_msec_format</span></code> (用于添加毫秒值)。</p>
</div>
</dd></dl>

<dl class="method">
<dt id="logging.Formatter.formatException">
<code class="sig-name descname">formatException</code><span class="sig-paren">(</span><em class="sig-param">exc_info</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter.formatException" title="永久链接至目标">¶</a></dt>
<dd><p>将指定的异常信息（由 <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> 返回的标准异常元组）格式化为字符串。 这个默认实现只使用了 <a class="reference internal" href="traceback.html#traceback.print_exception" title="traceback.print_exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.print_exception()</span></code></a>。 结果字符串将被返回。</p>
</dd></dl>

<dl class="method">
<dt id="logging.Formatter.formatStack">
<code class="sig-name descname">formatStack</code><span class="sig-paren">(</span><em class="sig-param">stack_info</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter.formatStack" title="永久链接至目标">¶</a></dt>
<dd><p>将指定的堆栈信息（由 <a class="reference internal" href="traceback.html#traceback.print_stack" title="traceback.print_stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.print_stack()</span></code></a> 返回的字符串，但移除末尾的换行符）格式化为字符串。 这个默认实现只是返回输入值。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="filter-objects">
<span id="filter"></span><h2>Filter 对象<a class="headerlink" href="#filter-objects" title="永久链接至标题">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">Filters</span></code> 可被 <code class="docutils literal notranslate"><span class="pre">Handlers</span></code> 和 <code class="docutils literal notranslate"><span class="pre">Loggers</span></code> 用来实现比按层级提供更复杂的过滤操作。 基本过滤器类只允许低于日志记录器层级结构中低于特定层级的事件。 例如，一个用 'A.B' 初始化的过滤器将允许 'A.B', 'A.B.C', 'A.B.C.D', 'A.B.D' 等日志记录器所记录的事件。 但 'A.BB', 'B.A.B' 等则不允许。 如果用空字符串初始化，则所有事件都会被略过。</p>
<dl class="class">
<dt id="logging.Filter">
<em class="property">class </em><code class="sig-prename descclassname">logging.</code><code class="sig-name descname">Filter</code><span class="sig-paren">(</span><em class="sig-param">name=''</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Filter" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个 <a class="reference internal" href="#logging.Filter" title="logging.Filter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Filter</span></code></a> 类的实例。 如果指定了 <em>name</em>，则它将被用来为日志记录器命名，该类及其子类将通过该过滤器允许指定事件通过。 如果 <em>name</em> 为空字符串，则允许所有事件通过。</p>
<dl class="method">
<dt id="logging.Filter.filter">
<code class="sig-name descname">filter</code><span class="sig-paren">(</span><em class="sig-param">record</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Filter.filter" title="永久链接至目标">¶</a></dt>
<dd><p>是否要记录指定的记录？返回零表示否，非零表示是。如果认为合适，则可以通过此方法就地修改记录。</p>
</dd></dl>

</dd></dl>

<p>请注意关联到处理程序的过滤器会在事件由处理程序发出之前被查询，而关联到日志记录器的过滤器则会在有事件被记录的的任何时候（使用 <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>, <a class="reference internal" href="#logging.info" title="logging.info"><code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code></a> 等等）在将事件发送给处理程序之前被查询。 这意味着由后代日志记录器生成的事件将不会被日志记录器的过滤器设置所过滤，除非该过滤器也已被应用于后代日志记录器。</p>
<p>你实际上不需要子类化 <code class="docutils literal notranslate"><span class="pre">Filter</span></code>: 你可以将传入任何包含 <code class="docutils literal notranslate"><span class="pre">filter</span></code> 方法的具有相同语义的的实例。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span>你不需要创建专门的 <code class="docutils literal notranslate"><span class="pre">Filter</span></code> 类，或使用具有 <code class="docutils literal notranslate"><span class="pre">filter</span></code> 方法的其他类：你可以使用一个函数（或其他可调用对象）作为过滤器。 过滤逻辑将检查过滤器对象是否文化的 <code class="docutils literal notranslate"><span class="pre">filter</span></code> 属性：如果有，就会将它当作是 <code class="docutils literal notranslate"><span class="pre">Filter</span></code> 并调用它的 <a class="reference internal" href="#logging.Filter.filter" title="logging.Filter.filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">filter()</span></code></a> 方法。 在其他情况下，则会将它当作是可调用对象并附带记录作为单一形参进行调用。 返回值应当与 <a class="reference internal" href="#logging.Filter.filter" title="logging.Filter.filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">filter()</span></code></a> 的返回值相一致。</p>
</div>
<p>Although filters are used primarily to filter records based on more
sophisticated criteria than levels, they get to see every record which is
processed by the handler or logger they're attached to: this can be useful if
you want to do things like counting how many records were processed by a
particular logger or handler, or adding, changing or removing attributes in
the LogRecord being processed. Obviously changing the LogRecord needs to be
done with some care, but it does allow the injection of contextual information
into logs (see <a class="reference internal" href="../howto/logging-cookbook.html#filters-contextual"><span class="std std-ref">使用过滤器传递上下文信息</span></a>).</p>
</div>
<div class="section" id="logrecord-objects">
<span id="log-record"></span><h2>LogRecord 属性<a class="headerlink" href="#logrecord-objects" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 实例是每当有日志被记录时由 <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> 自动创建的，并且可通过 <a class="reference internal" href="#logging.makeLogRecord" title="logging.makeLogRecord"><code class="xref py py-func docutils literal notranslate"><span class="pre">makeLogRecord()</span></code></a> 手动创建（例如根据从网络接收的已封存事件创建）。</p>
<dl class="class">
<dt id="logging.LogRecord">
<em class="property">class </em><code class="sig-prename descclassname">logging.</code><code class="sig-name descname">LogRecord</code><span class="sig-paren">(</span><em class="sig-param">name</em>, <em class="sig-param">level</em>, <em class="sig-param">pathname</em>, <em class="sig-param">lineno</em>, <em class="sig-param">msg</em>, <em class="sig-param">args</em>, <em class="sig-param">exc_info</em>, <em class="sig-param">func=None</em>, <em class="sig-param">sinfo=None</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.LogRecord" title="永久链接至目标">¶</a></dt>
<dd><p>包含与被记录的事件相关的所有信息。</p>
<p>主要信息是在 <code class="xref py py-attr docutils literal notranslate"><span class="pre">msg</span></code> 和 <code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code> 中传递的，它们使用 <code class="docutils literal notranslate"><span class="pre">msg</span> <span class="pre">%</span> <span class="pre">args</span></code> 组合到一起以创建记录的 <code class="xref py py-attr docutils literal notranslate"><span class="pre">message</span></code> 字段。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> -- 用于记录由此 LogRecord 所表示 的事件的日志记录器名称。 请注意此名称将始终为该值，即使它可以是由附加到不同（祖先）日志记录器的处理程序所发出的。</p></li>
<li><p><strong>level</strong> -- 以数字表示的日志记录事件层级（如 DEBUG, INFO 等）。 请注意这会转换为 LogRecord 的 <em>两个</em> 属性: <code class="docutils literal notranslate"><span class="pre">levelno</span></code> 为数字值而 <code class="docutils literal notranslate"><span class="pre">levelname</span></code> 为对应的层级名称。</p></li>
<li><p><strong>pathname</strong> -- 进行日志记录调用的文件的完整路径名。</p></li>
<li><p><strong>lineno</strong> -- 记录调用所在源文件中的行号。</p></li>
<li><p><strong>msg</strong> -- 事件描述消息，可能为带有可变数据占位符的格式字符串。</p></li>
<li><p><strong>args</strong> -- 要合并到 <em>msg</em> 参数以获得事件描述的可变数据。</p></li>
<li><p><strong>exc_info</strong> -- 包含当前异常信息的异常元组，或者如果没有可用异常信息则为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p></li>
<li><p><strong>func</strong> -- 发起调用日志记录调用的函数或方法名称。</p></li>
<li><p><strong>sinfo</strong> -- 一个文本字符串，表示当前线程中从堆栈底部直到日志记录调用的堆栈信息。</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="logging.LogRecord.getMessage">
<code class="sig-name descname">getMessage</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.LogRecord.getMessage" title="永久链接至目标">¶</a></dt>
<dd><p>在将 <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 实例与任何用户提供的参数合并之后，返回此实例的消息。 如果用户提供给日志记录调用的消息参数不是字符串，则会在其上调用 <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> 以将它转换为字符串。 此方法允许将用户定义的类用作消息，类的 <code class="docutils literal notranslate"><span class="pre">__str__</span></code> 方法可以返回要使用的实际格式字符串。</p>
</dd></dl>

<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span>The creation of a <code class="docutils literal notranslate"><span class="pre">LogRecord</span></code> has been made more configurable by
providing a factory which is used to create the record. The factory can be
set using <a class="reference internal" href="#logging.getLogRecordFactory" title="logging.getLogRecordFactory"><code class="xref py py-func docutils literal notranslate"><span class="pre">getLogRecordFactory()</span></code></a> and <a class="reference internal" href="#logging.setLogRecordFactory" title="logging.setLogRecordFactory"><code class="xref py py-func docutils literal notranslate"><span class="pre">setLogRecordFactory()</span></code></a>
(see this for the factory's signature).</p>
</div>
<p>This functionality can be used to inject your own values into a
LogRecord at creation time. You can use the following pattern:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">old_factory</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogRecordFactory</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">record_factory</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="n">record</span> <span class="o">=</span> <span class="n">old_factory</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">record</span><span class="o">.</span><span class="n">custom_attribute</span> <span class="o">=</span> <span class="mh">0xdecafbad</span>
    <span class="k">return</span> <span class="n">record</span>

<span class="n">logging</span><span class="o">.</span><span class="n">setLogRecordFactory</span><span class="p">(</span><span class="n">record_factory</span><span class="p">)</span>
</pre></div>
</div>
<p>通过此模式，多个工厂方法可以被链接起来，并且只要它们不重载彼此的属性或是在无意中覆盖了上面列出的标准属性，就不会发生意外。</p>
</dd></dl>

</div>
<div class="section" id="logrecord-attributes">
<span id="id2"></span><h2>LogRecord 属性<a class="headerlink" href="#logrecord-attributes" title="永久链接至标题">¶</a></h2>
<p>LogRecord 具有许多属性，它们大多数来自于传递给构造器的形参。 （请注意 LogRecord 构造器形参与 LogRecord 属性的名称并不总是完全彼此对应的。） 这些属性可被用于将来自记录的数据合并到格式字符串中。 下面的表格（按字母顺序）列出了属性名称、它们的含义以及相应的 %-style 格式字符串内占位符。</p>
<p>如果是使用 {}-格式化 (<a class="reference internal" href="stdtypes.html#str.format" title="str.format"><code class="xref py py-func docutils literal notranslate"><span class="pre">str.format()</span></code></a>)，你可以将 <code class="docutils literal notranslate"><span class="pre">{attrname}</span></code> 用作格式字符串内的占位符。 如果是使用 $-格式化 (<a class="reference internal" href="string.html#string.Template" title="string.Template"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Template</span></code></a>)，则会使用 <code class="docutils literal notranslate"><span class="pre">${attrname}</span></code> 的形式。 当然在这两种情况下，都应当将 <code class="docutils literal notranslate"><span class="pre">attrname</span></code> 替换为你想要使用的实际属性名称。</p>
<p>在 {}-格式化的情况下，你可以在属性名称之后放置指定的格式化旗标，并用冒号来分隔两者。 例如，占位符 <code class="docutils literal notranslate"><span class="pre">{msecs:03d}</span></code> 会将毫秒值 <code class="docutils literal notranslate"><span class="pre">4</span></code> 格式化为 <code class="docutils literal notranslate"><span class="pre">004</span></code>。 请参看 <a class="reference internal" href="stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> 文档了解你所能使用的选项的完整细节。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 18%" />
<col style="width: 28%" />
<col style="width: 53%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>属性名称</p></th>
<th class="head"><p>格式</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>args</p></td>
<td><p>不需要格式化。</p></td>
<td><p>合并到 <code class="docutils literal notranslate"><span class="pre">msg</span></code> 以产生 <code class="docutils literal notranslate"><span class="pre">message</span></code> 的包含参数的元组，或是其中的值将被用于合并的字典（当只有一个参数且其类型为字典时）。</p></td>
</tr>
<tr class="row-odd"><td><p>asctime</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(asctime)s</span></code></p></td>
<td><p>表示 <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 何时被创建的供人查看时间值。 默认形式为 '2003-07-08 16:49:45,896' (逗号之后的数字为时间的毫秒部分)。</p></td>
</tr>
<tr class="row-even"><td><p>created</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(created)f</span></code></p></td>
<td><p><a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 被创建的时间（即 <a class="reference internal" href="time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a> 的返回值）。</p></td>
</tr>
<tr class="row-odd"><td><p>exc_info</p></td>
<td><p>不需要格式化。</p></td>
<td><p>异常元组 (例如 <code class="docutils literal notranslate"><span class="pre">sys.exc_info</span></code>) 或者如未发生异常则为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p></td>
</tr>
<tr class="row-even"><td><p>filename</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(filename)s</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">pathname</span></code> 的文件名部分。</p></td>
</tr>
<tr class="row-odd"><td><p>funcName</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(funcName)s</span></code></p></td>
<td><p>函数名包括调用日志记录.</p></td>
</tr>
<tr class="row-even"><td><p>levelname</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(levelname)s</span></code></p></td>
<td><p>消息文本记录级别 (<code class="docutils literal notranslate"><span class="pre">'DEBUG'</span></code>, <code class="docutils literal notranslate"><span class="pre">'INFO'</span></code>, <code class="docutils literal notranslate"><span class="pre">'WARNING'</span></code>, <code class="docutils literal notranslate"><span class="pre">'ERROR'</span></code>, <code class="docutils literal notranslate"><span class="pre">'CRITICAL'</span></code>).</p></td>
</tr>
<tr class="row-odd"><td><p>levelno</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(levelno)s</span></code></p></td>
<td><p>消息数字记录级别 (<code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code>).</p></td>
</tr>
<tr class="row-even"><td><p>lineno</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(lineno)d</span></code></p></td>
<td><p>发出日志记录调用所在的源行号（如果可用）。</p></td>
</tr>
<tr class="row-odd"><td><p>message</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(message)s</span></code></p></td>
<td><p>记入日志的消息，即 <code class="docutils literal notranslate"><span class="pre">msg</span> <span class="pre">%</span> <span class="pre">args</span></code> 的结果。 这是在发起调用 <a class="reference internal" href="#logging.Formatter.format" title="logging.Formatter.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Formatter.format()</span></code></a> 时设置的。</p></td>
</tr>
<tr class="row-even"><td><p>module 模块</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(module)s</span></code></p></td>
<td><p>模块 (<code class="docutils literal notranslate"><span class="pre">filename</span></code> 的名称部分)。</p></td>
</tr>
<tr class="row-odd"><td><p>msecs</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(msecs)d</span></code></p></td>
<td><p><a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 被创建的时间的毫秒部分。</p></td>
</tr>
<tr class="row-even"><td><p>msg</p></td>
<td><p>不需要格式化。</p></td>
<td><p>在原始日志记录调用中传入的格式字符串。 与 <code class="docutils literal notranslate"><span class="pre">args</span></code> 合并以产生 <code class="docutils literal notranslate"><span class="pre">message</span></code>，或是一个任意对象 (参见 <a class="reference internal" href="../howto/logging.html#arbitrary-object-messages"><span class="std std-ref">使用任意对象作为消息</span></a>)。</p></td>
</tr>
<tr class="row-odd"><td><p>名称</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(name)s</span></code></p></td>
<td><p>用于记录调用的日志记录器名称。</p></td>
</tr>
<tr class="row-even"><td><p>pathname</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(pathname)s</span></code></p></td>
<td><p>发出日志记录调用的源文件的完整路径名（如果可用）。</p></td>
</tr>
<tr class="row-odd"><td><p>process</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(process)d</span></code></p></td>
<td><p>进程ID（如果可用）</p></td>
</tr>
<tr class="row-even"><td><p>processName</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(processName)s</span></code></p></td>
<td><p>进程名（如果可用）</p></td>
</tr>
<tr class="row-odd"><td><p>relativeCreated</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(relativeCreated)d</span></code></p></td>
<td><p>以毫秒数表示的 LogRecord 被创建的时间，即相对于 logging 模块被加载时间的差值。</p></td>
</tr>
<tr class="row-even"><td><p>stack_info</p></td>
<td><p>不需要格式化。</p></td>
<td><p>当前线程中从堆栈底部起向上直到包括日志记录调用并导致创建此记录的堆栈帧的堆栈帧信息（如果可用）。</p></td>
</tr>
<tr class="row-odd"><td><p>thread</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(thread)d</span></code></p></td>
<td><p>线程ID（如果可用）</p></td>
</tr>
<tr class="row-even"><td><p>threadName</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%(threadName)s</span></code></p></td>
<td><p>线程名（如果可用）</p></td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.1 版更改: </span>添加了 <em>processName</em></p>
</div>
</div>
<div class="section" id="loggeradapter-objects">
<span id="logger-adapter"></span><h2>LoggerAdapter 对象<a class="headerlink" href="#loggeradapter-objects" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a> 实例会被用来方便地将上下文信息传入日志记录调用。 要获取用法示例，请参阅 <a class="reference internal" href="../howto/logging-cookbook.html#context-info"><span class="std std-ref">添加上下文信息到你的日志记录输出</span></a> 部分。</p>
<dl class="class">
<dt id="logging.LoggerAdapter">
<em class="property">class </em><code class="sig-prename descclassname">logging.</code><code class="sig-name descname">LoggerAdapter</code><span class="sig-paren">(</span><em class="sig-param">logger</em>, <em class="sig-param">extra</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.LoggerAdapter" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个 <a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a> 的实例，该实例的初始化带有一个下层的 <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> 实例和一个字典类对象。</p>
<dl class="method">
<dt id="logging.LoggerAdapter.process">
<code class="sig-name descname">process</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.LoggerAdapter.process" title="永久链接至目标">¶</a></dt>
<dd><p>修改传递给日志记录调用的消息和/或关键字参数以便插入上下文信息。 此实现接受以 <em>extra</em> 形式传给构造器的对象并使用 'extra' 键名将其加入 <em>kwargs</em>。 返回值为一个 (<em>msg</em>, <em>kwargs</em>) 元组，其中传入了（可能经过修改的）参数版本。</p>
</dd></dl>

</dd></dl>

<p>在上述方法之外，<a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a> 还支持 <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> 的下列方法: <a class="reference internal" href="#logging.Logger.debug" title="logging.Logger.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>, <a class="reference internal" href="#logging.Logger.info" title="logging.Logger.info"><code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code></a>, <a class="reference internal" href="#logging.Logger.warning" title="logging.Logger.warning"><code class="xref py py-meth docutils literal notranslate"><span class="pre">warning()</span></code></a>, <a class="reference internal" href="#logging.Logger.error" title="logging.Logger.error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">error()</span></code></a>, <a class="reference internal" href="#logging.Logger.exception" title="logging.Logger.exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exception()</span></code></a>, <a class="reference internal" href="#logging.Logger.critical" title="logging.Logger.critical"><code class="xref py py-meth docutils literal notranslate"><span class="pre">critical()</span></code></a>, <a class="reference internal" href="#logging.Logger.log" title="logging.Logger.log"><code class="xref py py-meth docutils literal notranslate"><span class="pre">log()</span></code></a>, <a class="reference internal" href="#logging.Logger.isEnabledFor" title="logging.Logger.isEnabledFor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isEnabledFor()</span></code></a>, <a class="reference internal" href="#logging.Logger.getEffectiveLevel" title="logging.Logger.getEffectiveLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getEffectiveLevel()</span></code></a>, <a class="reference internal" href="#logging.Logger.setLevel" title="logging.Logger.setLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setLevel()</span></code></a> 以及 <a class="reference internal" href="#logging.Logger.hasHandlers" title="logging.Logger.hasHandlers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">hasHandlers()</span></code></a>。 这些方法具有与它们在 <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> 中的对应方法相同的签名，因此你可以互换使用这两种类型的实例。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span><a class="reference internal" href="#logging.Logger.isEnabledFor" title="logging.Logger.isEnabledFor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isEnabledFor()</span></code></a>, <a class="reference internal" href="#logging.Logger.getEffectiveLevel" title="logging.Logger.getEffectiveLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getEffectiveLevel()</span></code></a>, <a class="reference internal" href="#logging.Logger.setLevel" title="logging.Logger.setLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setLevel()</span></code></a> 和 <a class="reference internal" href="#logging.Logger.hasHandlers" title="logging.Logger.hasHandlers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">hasHandlers()</span></code></a> 方法已被添加到 <a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a>。 这些方法会委托给下层的日志记录器。</p>
</div>
</div>
<div class="section" id="thread-safety">
<h2>线程安全<a class="headerlink" href="#thread-safety" title="永久链接至标题">¶</a></h2>
<p>logging 模块的目标是使客户端不必执行任何特殊操作即可确保线程安全。 它通过使用线程锁来达成这个目标；用一个锁来序列化对模块共享数据的访问，并且每个处理程序也会创建一个锁来序列化对其下层 I/O 的访问。</p>
<p>如果你要使用 <a class="reference internal" href="signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> 模块来实现异步信号处理程序，则可能无法在这些处理程序中使用 logging。 这是因为 <a class="reference internal" href="threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> 模块中的锁实现并非总是可重入的，所以无法从此类信号处理程序发起调用。</p>
</div>
<div class="section" id="module-level-functions">
<h2>模块级别函数<a class="headerlink" href="#module-level-functions" title="永久链接至标题">¶</a></h2>
<p>在上述的类之外，还有一些模块层级的函数。</p>
<dl class="function">
<dt id="logging.getLogger">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">getLogger</code><span class="sig-paren">(</span><em class="sig-param">name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.getLogger" title="永久链接至目标">¶</a></dt>
<dd><p>Return a logger with the specified name or, if name is <code class="docutils literal notranslate"><span class="pre">None</span></code>, return a
logger which is the root logger of the hierarchy. If specified, the name is
typically a dot-separated hierarchical name like <em>'a'</em>, <em>'a.b'</em> or <em>'a.b.c.d'</em>.
Choice of these names is entirely up to the developer who is using logging.</p>
<p>All calls to this function with a given name return the same logger instance.
This means that logger instances never need to be passed between different parts
of an application.</p>
</dd></dl>

<dl class="function">
<dt id="logging.getLoggerClass">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">getLoggerClass</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.getLoggerClass" title="永久链接至目标">¶</a></dt>
<dd><p>Return either the standard <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> class, or the last class passed to
<a class="reference internal" href="#logging.setLoggerClass" title="logging.setLoggerClass"><code class="xref py py-func docutils literal notranslate"><span class="pre">setLoggerClass()</span></code></a>. This function may be called from within a new class
definition, to ensure that installing a customized <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> class will
not undo customizations already applied by other code. For example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyLogger</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">getLoggerClass</span><span class="p">()):</span>
    <span class="c1"># ... override behaviour here</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.getLogRecordFactory">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">getLogRecordFactory</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.getLogRecordFactory" title="永久链接至目标">¶</a></dt>
<dd><p>Return a callable which is used to create a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能: </span>This function has been provided, along with <a class="reference internal" href="#logging.setLogRecordFactory" title="logging.setLogRecordFactory"><code class="xref py py-func docutils literal notranslate"><span class="pre">setLogRecordFactory()</span></code></a>,
to allow developers more control over how the <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>
representing a logging event is constructed.</p>
</div>
<p>See <a class="reference internal" href="#logging.setLogRecordFactory" title="logging.setLogRecordFactory"><code class="xref py py-func docutils literal notranslate"><span class="pre">setLogRecordFactory()</span></code></a> for more information about the how the
factory is called.</p>
</dd></dl>

<dl class="function">
<dt id="logging.debug">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">debug</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.debug" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code> on the root logger. The <em>msg</em> is the
message format string, and the <em>args</em> are the arguments which are merged into
<em>msg</em> using the string formatting operator. (Note that this means that you can
use keywords in the format string, together with a single dictionary argument.)</p>
<p>There are three keyword arguments in <em>kwargs</em> which are inspected: <em>exc_info</em>
which, if it does not evaluate as false, causes exception information to be
added to the logging message. If an exception tuple (in the format returned by
<a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a>) or an exception instance is provided, it is used;
otherwise, <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> is called to get the exception information.</p>
<p>第二个可选关键字参数是 <em>stack_info</em>，默认为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。如果为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则将堆栈信息添加到日志消息中，包括实际的日志调用。请注意，这与通过指定 <em>exc_info</em> 显示的堆栈信息不同：前者是从堆栈底部到当前线程中的日志记录调用的堆栈帧，而后者是在搜索异常处理程序时，跟踪异常而打开的堆栈帧的信息。</p>
<p>您可以独立于 <em>exc_info</em> 来指定 <em>stack_info</em>，例如，即使在未引发任何异常的情况下，也可以显示如何到达代码中的特定点。堆栈帧在标题行之后打印：</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Stack (most recent call last):
</pre></div>
</div>
<p>这模仿了显示异常帧时所使用的 <code class="docutils literal notranslate"><span class="pre">Traceback</span> <span class="pre">(most</span> <span class="pre">recent</span> <span class="pre">call</span> <span class="pre">last):</span></code> 。</p>
<p>The third optional keyword argument is <em>extra</em> which can be used to pass a
dictionary which is used to populate the __dict__ of the LogRecord created for
the logging event with user-defined attributes. These custom attributes can then
be used as you like. For example, they could be incorporated into logged
messages. For example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">FORMAT</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%(asctime)-15s</span><span class="s1"> </span><span class="si">%(clientip)s</span><span class="s1"> </span><span class="si">%(user)-8s</span><span class="s1"> </span><span class="si">%(message)s</span><span class="s1">&#39;</span>
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="nb">format</span><span class="o">=</span><span class="n">FORMAT</span><span class="p">)</span>
<span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;clientip&#39;</span><span class="p">:</span> <span class="s1">&#39;192.168.0.1&#39;</span><span class="p">,</span> <span class="s1">&#39;user&#39;</span><span class="p">:</span> <span class="s1">&#39;fbloggs&#39;</span><span class="p">}</span>
<span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;Protocol problem: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="s1">&#39;connection reset&#39;</span><span class="p">,</span> <span class="n">extra</span><span class="o">=</span><span class="n">d</span><span class="p">)</span>
</pre></div>
</div>
<p>would print something like:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>2006-02-08 22:20:02,165 192.168.0.1 fbloggs  Protocol problem: connection reset
</pre></div>
</div>
<p>The keys in the dictionary passed in <em>extra</em> should not clash with the keys used
by the logging system. (See the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> documentation for more
information on which keys are used by the logging system.)</p>
<p>If you choose to use these attributes in logged messages, you need to exercise
some care. In the above example, for instance, the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> has been
set up with a format string which expects 'clientip' and 'user' in the attribute
dictionary of the LogRecord. If these are missing, the message will not be
logged because a string formatting exception will occur. So in this case, you
always need to pass the <em>extra</em> dictionary with these keys.</p>
<p>尽管这可能很烦人，但此功能旨在用于特殊情况，例如在多个上下文中执行相同代码的多线程服务器，并且出现的有趣条件取决于此上下文（例如在上面的示例中就是远程客户端IP地址和已验证用户名）。在这种情况下，很可能将专门的 <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> 与特定的 <a class="reference internal" href="#logging.Handler" title="logging.Handler"><code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code></a> 一起使用。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能: </span>增加了 <em>stack_info</em> 参数。</p>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.info">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">info</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.info" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> on the root logger. The arguments are
interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="logging.warning">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">warning</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.warning" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code> on the root logger. The arguments
are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>There is an obsolete function <code class="docutils literal notranslate"><span class="pre">warn</span></code> which is functionally
identical to <code class="docutils literal notranslate"><span class="pre">warning</span></code>. As <code class="docutils literal notranslate"><span class="pre">warn</span></code> is deprecated, please do not use
it - use <code class="docutils literal notranslate"><span class="pre">warning</span></code> instead.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.error">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">error</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.error" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> on the root logger. The arguments are
interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="logging.critical">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">critical</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.critical" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code> on the root logger. The arguments
are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="logging.exception">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">exception</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.exception" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> on the root logger. The arguments are
interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>. Exception info is added to the logging
message. This function should only be called from an exception handler.</p>
</dd></dl>

<dl class="function">
<dt id="logging.log">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">log</code><span class="sig-paren">(</span><em class="sig-param">level</em>, <em class="sig-param">msg</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.log" title="永久链接至目标">¶</a></dt>
<dd><p>Logs a message with level <em>level</em> on the root logger. The other arguments are
interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>The above module-level convenience functions, which delegate to the
root logger, call <a class="reference internal" href="#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a> to ensure that at least one handler
is available. Because of this, they should <em>not</em> be used in threads,
in versions of Python earlier than 2.7.1 and 3.2, unless at least one
handler has been added to the root logger <em>before</em> the threads are
started. In earlier versions of Python, due to a thread safety shortcoming
in <a class="reference internal" href="#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a>, this can (under rare circumstances) lead to
handlers being added multiple times to the root logger, which can in turn
lead to multiple messages for the same event.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.disable">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">disable</code><span class="sig-paren">(</span><em class="sig-param">level=CRITICAL</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.disable" title="永久链接至目标">¶</a></dt>
<dd><p>Provides an overriding level <em>level</em> for all loggers which takes precedence over
the logger's own level. When the need arises to temporarily throttle logging
output down across the whole application, this function can be useful. Its
effect is to disable all logging calls of severity <em>level</em> and below, so that
if you call it with a value of INFO, then all INFO and DEBUG events would be
discarded, whereas those of severity WARNING and above would be processed
according to the logger's effective level. If
<code class="docutils literal notranslate"><span class="pre">logging.disable(logging.NOTSET)</span></code> is called, it effectively removes this
overriding level, so that logging output again depends on the effective
levels of individual loggers.</p>
<p>Note that if you have defined any custom logging level higher than
<code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code> (this is not recommended), you won't be able to rely on the
default value for the <em>level</em> parameter, but will have to explicitly supply a
suitable value.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版更改: </span>The <em>level</em> parameter was defaulted to level <code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code>. See Issue
#28524 for more information about this change.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.addLevelName">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">addLevelName</code><span class="sig-paren">(</span><em class="sig-param">level</em>, <em class="sig-param">levelName</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.addLevelName" title="永久链接至目标">¶</a></dt>
<dd><p>Associates level <em>level</em> with text <em>levelName</em> in an internal dictionary, which is
used to map numeric levels to a textual representation, for example when a
<a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> formats a message. This function can also be used to define
your own levels. The only constraints are that all levels used must be
registered using this function, levels should be positive integers and they
should increase in increasing order of severity.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>If you are thinking of defining your own levels, please see the
section on <a class="reference internal" href="../howto/logging.html#custom-levels"><span class="std std-ref">自定义级别</span></a>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.getLevelName">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">getLevelName</code><span class="sig-paren">(</span><em class="sig-param">level</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.getLevelName" title="永久链接至目标">¶</a></dt>
<dd><p>Returns the textual representation of logging level <em>level</em>. If the level is one
of the predefined levels <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code>,
<code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> or <code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code> then you get the corresponding string. If you
have associated levels with names using <a class="reference internal" href="#logging.addLevelName" title="logging.addLevelName"><code class="xref py py-func docutils literal notranslate"><span class="pre">addLevelName()</span></code></a> then the name you
have associated with <em>level</em> is returned. If a numeric value corresponding to one
of the defined levels is passed in, the corresponding string representation is
returned. Otherwise, the string 'Level %s' % level is returned.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>Levels are internally integers (as they need to be compared in the
logging logic). This function is used to convert between an integer level
and the level name displayed in the formatted log output by means of the
<code class="docutils literal notranslate"><span class="pre">%(levelname)s</span></code> format specifier (see <a class="reference internal" href="#logrecord-attributes"><span class="std std-ref">LogRecord 属性</span></a>).</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.4 版更改: </span>In Python versions earlier than 3.4, this function could also be passed a
text level, and would return the corresponding numeric value of the level.
This undocumented behaviour was considered a mistake, and was removed in
Python 3.4, but reinstated in 3.4.2 due to retain backward compatibility.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.makeLogRecord">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">makeLogRecord</code><span class="sig-paren">(</span><em class="sig-param">attrdict</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.makeLogRecord" title="永久链接至目标">¶</a></dt>
<dd><p>Creates and returns a new <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> instance whose attributes are
defined by <em>attrdict</em>. This function is useful for taking a pickled
<a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> attribute dictionary, sent over a socket, and reconstituting
it as a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> instance at the receiving end.</p>
</dd></dl>

<dl class="function">
<dt id="logging.basicConfig">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">basicConfig</code><span class="sig-paren">(</span><em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.basicConfig" title="永久链接至目标">¶</a></dt>
<dd><p>Does basic configuration for the logging system by creating a
<a class="reference internal" href="logging.handlers.html#logging.StreamHandler" title="logging.StreamHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamHandler</span></code></a> with a default <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> and adding it to the
root logger. The functions <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>, <a class="reference internal" href="#logging.info" title="logging.info"><code class="xref py py-func docutils literal notranslate"><span class="pre">info()</span></code></a>, <a class="reference internal" href="#logging.warning" title="logging.warning"><code class="xref py py-func docutils literal notranslate"><span class="pre">warning()</span></code></a>,
<a class="reference internal" href="#logging.error" title="logging.error"><code class="xref py py-func docutils literal notranslate"><span class="pre">error()</span></code></a> and <a class="reference internal" href="#logging.critical" title="logging.critical"><code class="xref py py-func docutils literal notranslate"><span class="pre">critical()</span></code></a> will call <a class="reference internal" href="#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a> automatically
if no handlers are defined for the root logger.</p>
<p>This function does nothing if the root logger already has handlers
configured for it.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>This function should be called from the main thread
before other threads are started. In versions of Python prior to
2.7.1 and 3.2, if this function is called from multiple threads,
it is possible (in rare circumstances) that a handler will be added
to the root logger more than once, leading to unexpected results
such as messages being duplicated in the log.</p>
</div>
<p>支持以下关键字参数。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 24%" />
<col style="width: 76%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>格式</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><em>filename</em></p></td>
<td><p>使用指定的文件名而不是 StreamHandler 创建 FileHandler。</p></td>
</tr>
<tr class="row-odd"><td><p><em>filemode</em></p></td>
<td><p>如果指定了 <em>filename</em>，则用此 <a class="reference internal" href="functions.html#filemodes"><span class="std std-ref">模式</span></a> 打开该文件。 默认模式为 <code class="docutils literal notranslate"><span class="pre">'a'</span></code>。</p></td>
</tr>
<tr class="row-even"><td><p><em>format</em></p></td>
<td><p>处理器使用的指定格式字符串。</p></td>
</tr>
<tr class="row-odd"><td><p><em>datefmt</em></p></td>
<td><p>Use the specified date/time format, as
accepted by <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a>.</p></td>
</tr>
<tr class="row-even"><td><p><em>style</em></p></td>
<td><p>If <em>format</em> is specified, use this style
for the format string. One of <code class="docutils literal notranslate"><span class="pre">'%'</span></code>,
<code class="docutils literal notranslate"><span class="pre">'{'</span></code> or <code class="docutils literal notranslate"><span class="pre">'$'</span></code> for <a class="reference internal" href="stdtypes.html#old-string-formatting"><span class="std std-ref">printf-style</span></a>,
<a class="reference internal" href="stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> or
<a class="reference internal" href="string.html#string.Template" title="string.Template"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Template</span></code></a> respectively.
Defaults to <code class="docutils literal notranslate"><span class="pre">'%'</span></code>.</p></td>
</tr>
<tr class="row-odd"><td><p><em>level</em></p></td>
<td><p>设置根记录器级别去指定 <a class="reference internal" href="#levels"><span class="std std-ref">level</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><em>stream</em></p></td>
<td><p>使用指定的流初始化 StreamHandler。 请注意此参数与 <em>filename</em> 是不兼容的 - 如果两者同时存在，则会引发 <code class="docutils literal notranslate"><span class="pre">ValueError</span></code>。</p></td>
</tr>
<tr class="row-odd"><td><p><em>handlers</em></p></td>
<td><p>If specified, this should be an iterable of
already created handlers to add to the root
logger. Any handlers which don't already
have a formatter set will be assigned the
default formatter created in this function.
Note that this argument is incompatible
with <em>filename</em> or <em>stream</em> - if both
are present, a <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> is raised.</p></td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span>增加了 <em>style</em> 参数。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.3 版更改: </span>The <em>handlers</em> argument was added. Additional checks were added to
catch situations where incompatible arguments are specified (e.g.
<em>handlers</em> together with <em>stream</em> or <em>filename</em>, or <em>stream</em>
together with <em>filename</em>).</p>
</div>
</dd></dl>

<dl class="function">
<dt id="logging.shutdown">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">shutdown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.shutdown" title="永久链接至目标">¶</a></dt>
<dd><p>Informs the logging system to perform an orderly shutdown by flushing and
closing all handlers. This should be called at application exit and no
further use of the logging system should be made after this call.</p>
</dd></dl>

<dl class="function">
<dt id="logging.setLoggerClass">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">setLoggerClass</code><span class="sig-paren">(</span><em class="sig-param">klass</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.setLoggerClass" title="永久链接至目标">¶</a></dt>
<dd><p>Tells the logging system to use the class <em>klass</em> when instantiating a logger.
The class should define <a class="reference internal" href="../reference/datamodel.html#object.__init__" title="object.__init__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code></a> such that only a name argument is
required, and the <a class="reference internal" href="../reference/datamodel.html#object.__init__" title="object.__init__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code></a> should call <code class="xref py py-meth docutils literal notranslate"><span class="pre">Logger.__init__()</span></code>. This
function is typically called before any loggers are instantiated by applications
which need to use custom logger behavior. After this call, as at any other
time, do not instantiate loggers directly using the subclass: continue to use
the <a class="reference internal" href="#logging.getLogger" title="logging.getLogger"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.getLogger()</span></code></a> API to get your loggers.</p>
</dd></dl>

<dl class="function">
<dt id="logging.setLogRecordFactory">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">setLogRecordFactory</code><span class="sig-paren">(</span><em class="sig-param">factory</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.setLogRecordFactory" title="永久链接至目标">¶</a></dt>
<dd><p>Set a callable which is used to create a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>factory</strong> -- The factory callable to be used to instantiate a log record.</p>
</dd>
</dl>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能: </span>This function has been provided, along with <a class="reference internal" href="#logging.getLogRecordFactory" title="logging.getLogRecordFactory"><code class="xref py py-func docutils literal notranslate"><span class="pre">getLogRecordFactory()</span></code></a>, to
allow developers more control over how the <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> representing
a logging event is constructed.</p>
</div>
<p>The factory has the following signature:</p>
<p><code class="docutils literal notranslate"><span class="pre">factory(name,</span> <span class="pre">level,</span> <span class="pre">fn,</span> <span class="pre">lno,</span> <span class="pre">msg,</span> <span class="pre">args,</span> <span class="pre">exc_info,</span> <span class="pre">func=None,</span> <span class="pre">sinfo=None,</span> <span class="pre">**kwargs)</span></code></p>
<blockquote>
<div><dl class="field-list simple">
<dt class="field-odd">名称</dt>
<dd class="field-odd"><p>日志记录器名称</p>
</dd>
<dt class="field-even">level</dt>
<dd class="field-even"><p>日志记录级别（数字）。</p>
</dd>
<dt class="field-odd">fn</dt>
<dd class="field-odd"><p>进行日志记录调用的文件的完整路径名。</p>
</dd>
<dt class="field-even">lno</dt>
<dd class="field-even"><p>记录调用所在文件中的行号。</p>
</dd>
<dt class="field-odd">msg</dt>
<dd class="field-odd"><p>日志消息。</p>
</dd>
<dt class="field-even">args</dt>
<dd class="field-even"><p>日志记录消息的参数。</p>
</dd>
<dt class="field-odd">exc_info</dt>
<dd class="field-odd"><p>异常元组，或 <code class="docutils literal notranslate"><span class="pre">None</span></code> 。</p>
</dd>
<dt class="field-even">func</dt>
<dd class="field-even"><p>调用日志记录调用的函数或方法的名称。</p>
</dd>
<dt class="field-odd">sinfo</dt>
<dd class="field-odd"><p>A stack traceback such as is provided by
<a class="reference internal" href="traceback.html#traceback.print_stack" title="traceback.print_stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.print_stack()</span></code></a>, showing the call hierarchy.</p>
</dd>
<dt class="field-even">kwargs</dt>
<dd class="field-even"><p>其他关键字参数。</p>
</dd>
</dl>
</div></blockquote>
</dd></dl>

</div>
<div class="section" id="module-level-attributes">
<h2>模块级属性<a class="headerlink" href="#module-level-attributes" title="永久链接至标题">¶</a></h2>
<dl class="attribute">
<dt id="logging.lastResort">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">lastResort</code><a class="headerlink" href="#logging.lastResort" title="永久链接至目标">¶</a></dt>
<dd><p>A &quot;handler of last resort&quot; is available through this attribute. This
is a <a class="reference internal" href="logging.handlers.html#logging.StreamHandler" title="logging.StreamHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamHandler</span></code></a> writing to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> with a level of
<code class="docutils literal notranslate"><span class="pre">WARNING</span></code>, and is used to handle logging events in the absence of any
logging configuration. The end result is to just print the message to
<code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>. This replaces the earlier error message saying that
&quot;no handlers could be found for logger XYZ&quot;. If you need the earlier
behaviour for some reason, <code class="docutils literal notranslate"><span class="pre">lastResort</span></code> can be set to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

</div>
<div class="section" id="integration-with-the-warnings-module">
<h2>与警告模块集成<a class="headerlink" href="#integration-with-the-warnings-module" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="#logging.captureWarnings" title="logging.captureWarnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">captureWarnings()</span></code></a> 函数可用来将 <a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> 和 <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> 模块集成。</p>
<dl class="function">
<dt id="logging.captureWarnings">
<code class="sig-prename descclassname">logging.</code><code class="sig-name descname">captureWarnings</code><span class="sig-paren">(</span><em class="sig-param">capture</em><span class="sig-paren">)</span><a class="headerlink" href="#logging.captureWarnings" title="永久链接至目标">¶</a></dt>
<dd><p>此函数用于打开和关闭日志系统对警告的捕获。</p>
<p>如果 <em>capture</em> 是 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则 <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> 模块发出的警告将重定向到日志记录系统。具体来说，将使用 <a class="reference internal" href="warnings.html#warnings.formatwarning" title="warnings.formatwarning"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.formatwarning()</span></code></a> 格式化警告信息，并将结果字符串使用 <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code> 等级记录到名为 <code class="docutils literal notranslate"><span class="pre">'py.warnings'</span></code> 的记录器中。</p>
<p>如果 <em>capture</em> 是 <code class="docutils literal notranslate"><span class="pre">False</span></code>，则将停止将警告重定向到日志记录系统，并且将警告重定向到其原始目标（即在  <code class="docutils literal notranslate"><span class="pre">captureWarnings(True)</span></code>  调用之前的有效目标）。</p>
</dd></dl>

<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt>模块 <a class="reference internal" href="logging.config.html#module-logging.config" title="logging.config: Configuration of the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.config</span></code></a></dt><dd><p>日志记录模块的配置 API 。</p>
</dd>
<dt>模块 <a class="reference internal" href="logging.handlers.html#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a></dt><dd><p>日志记录模块附带的有用处理程序。</p>
</dd>
<dt><span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0282"><strong>PEP 282</strong></a> - Logging 系统</dt><dd><p>该提案描述了Python标准库中包含的这个特性。</p>
</dd>
<dt><a class="reference external" href="https://www.red-dove.com/python_logging.html">Original Python logging package</a></dt><dd><p>这是该 <a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> 包的原始来源。该站点提供的软件包版本适用于 Python 1.5.2、2.1.x 和 2.2.x，它们不被 <a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> 包含在标准库中。</p>
</dd>
</dl>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">目录</a></h3>
  <ul>
<li><a class="reference internal" href="#">模块 <code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code> --- Python 的日志记录工具</a><ul>
<li><a class="reference internal" href="#logger-objects">Logger 对象</a></li>
<li><a class="reference internal" href="#logging-levels">日志级别</a></li>
<li><a class="reference internal" href="#handler-objects">处理器对象</a></li>
<li><a class="reference internal" href="#formatter-objects">格式器对象</a></li>
<li><a class="reference internal" href="#filter-objects">Filter 对象</a></li>
<li><a class="reference internal" href="#logrecord-objects">LogRecord 属性</a></li>
<li><a class="reference internal" href="#logrecord-attributes">LogRecord 属性</a></li>
<li><a class="reference internal" href="#loggeradapter-objects">LoggerAdapter 对象</a></li>
<li><a class="reference internal" href="#thread-safety">线程安全</a></li>
<li><a class="reference internal" href="#module-level-functions">模块级别函数</a></li>
<li><a class="reference internal" href="#module-level-attributes">模块级属性</a></li>
<li><a class="reference internal" href="#integration-with-the-warnings-module">与警告模块集成</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="getopt.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">getopt</span></code> --- C 风格的命令行选项解析器</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="logging.config.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.config</span></code> --- 日志记录配置</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/logging.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="logging.config.html" title="logging.config --- 日志记录配置"
             >下一页</a> |</li>
        <li class="right" >
          <a href="getopt.html" title="getopt --- C 风格的命令行选项解析器"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="allos.html" >通用操作系统服务</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>